package com.erp.module.YuliaoPrint

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.contacts.Contacts
import com.erp.util.Httputil.*
import org.xutils.http.RequestParams
import org.xutils.x

class YuliaoPrintModel {
    /**获取余料开料列表*/
    fun getYuliaoList(context: Context, page: Int, pagesize: Int, bean : FragmengtYuliaoPrintLabel.SousuoBean, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.YULIAO_PRINT_ORDER)
        getparams(context, params)
        setProsess(params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        params.addBodyParameter("searchParams[mc_id]", bean.mc_id)
        params.addBodyParameter("searchParams[biaoji]", bean.isbiaoji)
//        params.addBodyParameter("searchParams[mb_area_num]", bean.mb_area_num)
        Log.d("getOemList",bean.mc_id)
        var areas = bean.mb_area_num.split(",")
        for (i in areas.indices){
            params.addBodyParameter("searchParams[mb_area_num]["+i+"]", areas[i])
        }
        params.addBodyParameter("searchParams[color_color_mh]", bean.color_color_mh)
        if(bean.time_category != ""){
            params.addBodyParameter("searchParams[time_filter][time_category]", bean.time_category)
            params.addBodyParameter("searchParams[time_filter][start_time]", bean.start_time)
            params.addBodyParameter("searchParams[time_filter][end_time]", bean.end_time)
        }
        if(bean.width != ""){
            var width = bean.width.toInt()
            var m_width = (width-100).toString()+"到"+width
            params.addBodyParameter("searchParams[m_width]", m_width)
        }
        if(bean.height != ""){
            var height = bean.height.toInt()
            var m_height = (height-100).toString()+"到"+height
            params.addBodyParameter("searchParams[m_length]", m_height)
        }
        x.http().get(params, Call(context, onUserDataInterface))
    }

    /**获取物料类别代码 */
    fun getWuLiao_LeiBie_DaiMa(context: Context, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.YULIAO_PRINT_ORDER+"/configuration/material_category")
        getparams(context, params)
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }

    /**获取开料员工代码 */
    fun getWage_user(context: Context, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.YULIAO_PRINT_ORDER+"/configuration/wage_user")
        getparams(context, params)
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }

    /**s上传标记 */
    fun postIdentifying_yuliao(context: Context,mid:String,position: String,kailiao_time:String,kailiao_wu_id:String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.YULIAO_PRINT_ORDER+"/identifying_yuliao")
        getparams(context, params)
        addtoken(params)
        Log.d("postIdentifying_yuliao","sssssssssss"+mid)
        Log.d("postIdentifying_yuliao","position"+position)
        Log.d("postIdentifying_yuliao","kailiao_wu_id"+kailiao_time)
        Log.d("postIdentifying_yuliao","kailiao_wu_id"+kailiao_wu_id)
        params.addBodyParameter("mid", mid,Contacts.BOUNDARY)
        params.addBodyParameter("position", position,Contacts.BOUNDARY)
        params.addBodyParameter("kailiao_time", kailiao_time,Contacts.BOUNDARY)
        params.addBodyParameter("kailiao_wu_id", kailiao_wu_id,Contacts.BOUNDARY)
        params.addHeader("ACCEPT", "application/json")
        x.http().post<String>(params, Call(context, onUserDataInterface))
    }
 }